/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-09-09
 * Time: 17:43
 */
public class is_Happy {
    public static boolean isHappy(int n) {
        int fast=Happy(n);
        int slow=n;
        while (fast!=slow){
            fast=Happy(fast);
            fast=Happy(fast);
            slow=Happy(slow);
        }
        return slow==1;
    }

    public static int Happy(int n) {
        if (n<10){
            return n*n;
        }
        int m=n%10;

        return m*m+Happy(n/10);
    }

    public static void main(String[] args) {
        int a=19;
        System.out.println(Happy(a));
        System.out.println(isHappy(a));
    }
}
